package com.qf.service.impl;

import com.qf.entity.SysUserRoleKey;
import com.qf.exceptions.AddDataException;
import com.qf.exceptions.ResultCode;
import com.qf.mapper.SysUserRoleDao;
import com.qf.pojo.CheckType;
import com.qf.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

/**
 * @Author ztf
 * @Date 19:53 2022/1/10
 **/
@Service
@Transactional(rollbackFor = RuntimeException.class)
public class UserRoleServiceImpl implements UserRoleService {
    private SysUserRoleDao sysUserRoleDao;

    @Autowired
    public void setSysUserRoleDao(SysUserRoleDao sysUserRoleDao) {
        this.sysUserRoleDao = sysUserRoleDao;
    }

    @Override
    public void addUserRole(SysUserRoleKey userRoleKey) {
        Assert.isTrue(userRoleKey.isEmpty(CheckType.ADD), () -> {
            throw new AddDataException("添加用户角色，参数错误", ResultCode.FAIL);
        });
        sysUserRoleDao.insert(userRoleKey);
    }
}
